import { computed } from "vue";

export const useVModel = (props: any, propName: keyof typeof props, emit: (...args: any[]) => any) => {
    return computed({
        get: () => {
            return new Proxy(props[propName], {
                set: (target, key, value) => {
                    target[key] = value;
                    emit("update:modelValue", target);
                    return true;
                }
            });
        },
        set: newValue => {
            emit("update:modelValue", newValue);
            return true;
        }
    });
};
